<!DOCTYPE html>
<html class="ui-page-login">

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<link href="css/mui.min.css" rel="stylesheet" />
		<link href="css/style.css" rel="stylesheet" />
		<link href="css/loading.css" rel="stylesheet" />

		<style>
			.area {
				margin: 20px auto 0px auto;
			}
			.mui-input-group:first-child {
				margin-top: 20px;
			}
			.mui-input-group label {
				width: 22%;
			}
			.mui-input-row label~input,
			.mui-input-row label~select,
			.mui-input-row label~textarea {
				width: 78%;
			}
			.mui-checkbox input[type=checkbox],
			.mui-radio input[type=radio] {
				top: 6px;
			}
			.mui-content-padded {
				margin-top: 25px;
			}
			.mui-btn {
				padding: 10px;
			}
			.mui-title{
				text-align: right;
			}
			/*.mui-bar-nav{
				box-shadow:0 1px 6px #efeff4;
			}
			.mui-bar{
				background-color:#efeff4;
			}*/
			.mui-bar .mui-title{
				right:18px;
			}
				.link-area {
				display: block;
				margin-top: 25px;
				text-align: center;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">注册</h1>
		</header>
		<div class="mui-content">
			<div class="mui-content-padded" style="text-align: center;">
			   <h1>码寻</h1>
			</div>
			<form id="userForm" class="mui-input-group">
				<div class="mui-input-row">
					<label>昵称<span style="color:red">*</span></label>
					<input id='nickname' name="nickname" type="text" class="mui-input-clear mui-input" placeholder="请输入用户名">
				</div>
				<div class="mui-input-row">
					<label>密码<span style="color:red">*</span></label>
					<input id='password' name="password" type="password" class="mui-input-clear mui-input" placeholder="请输入密码">
				</div>
				<div class="mui-input-row">
					<label>姓名</label>
					<input id='username' name="username" type="text" class="mui-input-clear mui-input" placeholder="请输入真实姓名">
				</div>
				<div class="mui-input-row">
					<label>手机<span style="color:red">*</span></label>
					<input id='phone' name="phone" type="number" class="mui-input-clear mui-input" placeholder="请输联系方式">
				</div>
				<div class="mui-input-row">
					<label>邮箱<span style="color:red">*</span></label>
					<input id='email' name="email"  type="email" class="mui-input-clear mui-input" placeholder="请输入邮箱">
				</div>
				<div class="mui-input-row">
					<label>微信</label>
					<input id='wechat' name="wechat"  type="email" class="mui-input-clear mui-input" placeholder="请输入微信">
				</div>
				<div class="mui-input-row">
					<label>QQ</label>
					<input id='qq' name="qq" type="number" class="mui-input-clear mui-input" placeholder="请输入QQ">
				</div>
				<!--<input id="codeId" type="hidden" name="codeId" value=""/>-->
			</form>
			<div class="mui-content-padded">
				<button id='regsub'  class="mui-btn mui-btn-block mui-btn-primary">确认注册</button>
			</div>
			<div class="mui-content-padded">
				<div class="link-area"><a href="" id='dl'>登录账号（已有账号请点此登录完成绑定）</a> <span class="spliter"/></a></div>
			</div>
			<div id="bottom" style="text-align: center;margin-top: 10px;">
				<p>(c) Copyright 2018 maxun.xyz. All Rights Reserved.</p>
			</div>
		</div>
		<script src="js/mui.min.js"></script>

		<script src="js/app.js"></script>
		<script>
            mui.init()
		</script>

			<script src="js/jquery-1.8.3.js"></script>
			<script src="js/loading.js"></script>

			<script>
                // $(window).resize(function(){
                //     var h_doc = $(document).height();
                //     var h_foo = h_doc-25;
                //     $('#bottom').offset({top:h_foo,left:0});
                // });
                //获取url中的参数
                function getUrlParam(name) {
                    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
                    var r = window.location.search.substr(1).match(reg); //匹配目标参数
                    if (r != null) return unescape(r[2]); return null; //返回参数值
                }
                $(function () {
					$("#dl").attr("href","login.html?codeId="+getUrlParam("codeId"));
                })
                $("#regsub").click(function () {
                    var check=true;
                    mui("#userForm input").each(function() {
                        //若当前input为空，则alert提醒
                        if(this.name!="username"&&this.name!="wechat"&&this.name!="qq"){
                            if(!this.value || this.value.trim() == "") {
                                var label = this.previousElementSibling;
                                mui.alert(label.innerText.replace("*","") + "不允许为空");
                                check = false;
                                return false;
                            }
                        }

                    }); //校验通过，继续执行业务逻辑
                    if(check){
                        mui.showLoading("正在加载..","div");
                        $.post("../controller/UserController.php/?action=register",
                            {nickname:$("#nickname").val(),username:$("#username").val(),phone:$("#phone").val()
                                ,email:$("#email").val(),wechat:$("#wechat").val(),qq:$("#qq").val(),password:$("#password").val(),
                            codeId:getUrlParam("codeId")},
                            function(data,status) {
                                if (JSON.parse(data).message == "success") {
                                    mui.hideLoading();
									mui.alert("注册成功",function () {
                                        window.location.href = "login.html?id=" + JSON.parse(data).id;
                                    });
                                } else {
                                    mui.hideLoading();
                                    mui.alert("账号或者密码不正确")
                                    // window.location.reload();
                                }
                            });
                    }
                });
			</script>
			<script src="https://s13.cnzz.com/z_stat.php?id=1273362290&web_id=1273362290" language="JavaScript"></script>
	</body>

</html>